<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\SCloudLessonInfo as CloudLessonModel;

class CloudLessonController extends BaseController
{
    //获取云课堂列表
    public function getCloudLessonList()
    {
    	$list = CloudLessonModel::getList();
    	foreach ($list as &$item) {
    		$item->visit_num = $item->look_num + $item->base_num;
    		$item->look_num = 0;
    		$item->base_num = 0;
    	}
    	return $this->outPutSucc($list);
    }

    //获取云课堂单堂课
    public function getOneCloudLessonById()
    {
    	$lesson_id = intval( request("lessonId") );
    	if($lesson_id > 0) {

            $ret = CloudLessonModel::find($lesson_id);
            if($ret) {
                $this->addLookNum($ret);
                return $this->outPutSucc($ret);
            }
    	}

        return $this->outPutErr("无效的课程id！");
    }

    //添加播放次数
    protected function addLookNum($cloudLesson)
    {

        if ( $cloudLesson->is_free ) {
            $cloudLesson->look_num++;
            $cloudLesson->save();
            return;
        }

        
    }

    //检测用户是否有权限播放
    protected function checkUserCanLook($cloudLesson)
    {
        if ( $cloudLesson->is_free ) {
            return true;
        }

        //是否购买
        
        //是否分享够了
    }

}
